package com.yungu.swift.api.route.v2.passenger;

import com.alibaba.dubbo.config.annotation.Reference;
import com.yungu.swift.api.base.BaseApi;
import com.yungu.swift.base.ResponseData;
import com.yungu.swift.order.model.param.RefundParam;
import com.yungu.swift.order.service.RefundService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import static com.yungu.swift.api.base.ApiErrorEnum.PARAM_ERROR;

@RestController
@RequestMapping(value = "/api/v2/passenger/refund")
@Api(value = "【交易】【退款】乘客退款接口V2", tags = "V2-乘客退款接口")
public class PasRefundApi extends BaseApi {

    @Reference
    private RefundService refundService;

    @PostMapping(value = {"/create"})
    @ApiOperation(value = "创建退款接口", notes = "create")
    public ResponseData<Integer> create(@RequestBody RefundParam refundParam) {
        if (StringUtils.isEmpty(refundParam.getOrderUuid())) {
            return ResponseData.buildErrorResponse(PARAM_ERROR.getCode(), PARAM_ERROR.getMsg());
        }
        refundParam.setCreateBy(refundParam.getUserUuid());
        return refundService.refund(refundParam);
    }

    @PostMapping(value = {"/query"})
    @ApiOperation(value = "退款查询接口", notes = "query")
    public ResponseData<Boolean> query(@RequestBody RefundParam refundParam) {
        if (StringUtils.isEmpty(refundParam.getOrderUuid())) {
            return ResponseData.buildErrorResponse(PARAM_ERROR.getCode(), PARAM_ERROR.getMsg());
        }
        return refundService.refundQuery(refundParam.getOrderUuid(), refundParam.getUserUuid());
    }
}
